package com.goldsprite.infinityworld.screens.examples.ui;

import com.badlogic.gdx.scenes.scene2d.*;
import com.badlogic.gdx.scenes.scene2d.ui.*;
import com.badlogic.gdx.utils.*;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.goldsprite.gdxcore.logs.LogViewerService;
import com.goldsprite.gdxcore.screens.GScreen;
import com.goldsprite.gdxcore.utils.FontUtils;
import com.goldsprite.infinityworld.assets.GlobalAssets;

public class LogViewerExampleScreen extends GScreen {
	private static final Logger logger = new Logger(LogViewerExampleScreen.class.getName(), Logger.DEBUG);

	private Stage stage;

	private LogViewerService loggerService; // 引用 LoggerService

	public LogViewerExampleScreen() {
	}

	@Override
	public void create() {
		// 获取字体
		BitmapFont fnt = FontUtils.generate(20);
		// 加载 skin
		Skin skin = new Skin(Gdx.files.internal(GlobalAssets.skinPath));
		TextButton.TextButtonStyle textButtonStyle = skin.get(TextButton.TextButtonStyle.class);
		textButtonStyle.font = fnt;
		Label.LabelStyle labelStyle = skin.get(Label.LabelStyle.class);
		labelStyle.font = fnt;

		// 创建舞台
		stage = new Stage(getViewport());
		getImp().addProcessor(stage);

		// 初始化 LoggerService
		loggerService = new LogViewerService(skin, getViewCenter().x, getViewCenter().y, "Window");
		ScrollPane scrollPane = loggerService.getScrollPane();

		//将窗口添加到舞台
		stage.addActor(loggerService.getRootLayout());

		// 测试日志
		loggerService.log("测试默认日志1");
		loggerService.logDebug("测试调试日志1");
		loggerService.logInfo("测试信息日志1");
		String lengthStr = new String(new char[100]).replace("\0", "X");
		loggerService.logInfo("测试信息日志: 测试横向滑动: " + lengthStr);
		for (int i = 0; i < 50; i++)
			loggerService.logInfo("测试信息日志: 测试纵向滑动: " + "A");
		loggerService.logError("测试错误日志1");
	}

	@Override
	public void render(float delta) {
		super.render(delta);

		// 渲染舞台和处理输入
		stage.act(Math.min(Gdx.graphics.getDeltaTime(), 1 / 30f));
		stage.draw();
	}

	@Override
	public void dispose() {
		loggerService.dispose();
		stage.dispose();
	}

}
